<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="户号">
              <!-- <j-search-select-tag placeholder="请选择用户档案" v-model="queryParam.contactId" dict="mws_t_arc_contacts,name,id"/> -->
              <a-input placeholder="请输入户号" class="query-group-cust" v-model="queryParam.code"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="片区">
              <j-dict-select-tag placeholder="请选择片区" v-model="queryParam.areaId" dictCode="mws_t_base_areas,name,id"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="抄表本号">
              <j-dict-select-tag v-model="queryParam.bookId" placeholder="请选择抄表本号" dictCode="mws_t_mr_books,name,id"/>
            </a-form-item>
          </a-col>
          <!-- <a-col :xl="10" :lg="11" :md="12" :sm="24">
            <a-form-item label="账户余额">
              <a-input placeholder="请输入最小值" class="query-group-cust" v-model="queryParam.balance_begin"></a-input>
              <span class="query-group-split-cust"></span>
              <a-input placeholder="请输入最大值" class="query-group-cust" v-model="queryParam.balance_end"></a-input>
            </a-form-item>
          </a-col> -->
          <!-- <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="是否预开票">
                <j-dict-select-tag placeholder="请选择是否预开票" v-model="queryParam.isPreInvoiced" dictCode="yn"/>
              </a-form-item>
            </a-col>
          </template> -->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a> -->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('缴费账户')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <a-button type="primary" icon="notification" @click="handleMsgStop">停水通知</a-button> 
      <!-- 高级查询区域 -->
      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
      <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
    </div>

    <!-- table区域-begin -->
    <div>
      <!-- <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div> -->

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
         <template slot="ellipsisText" slot-scope="text">
          <j-ellipsis :value="text" :length="textMaxLength"></j-ellipsis>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleMeter(record.id)">关联水表</a>
          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleCancelBind(record)">解除绑定</a>
              </a-menu-item>
              <a-menu-item>
                <a @click="handleEdit(record)">编辑</a>
              </a-menu-item>
              <a-menu-item>
                <a @click="handleTabDetail(record.code)">账号详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <!-- 表单区域 -->
    <a-modal v-model:visible="wxtStopVisible" title="输入微信停水通知信息" @ok="handleWxtStopOk">
       <p> 停水类型：<j-dict-select-tag v-model="msgModel.msgType" placeholder="请选择通知类型" style="width:100%" dictCode="water_stop_type"/>  
       <p> 停水时间段：<a-input placeholder="2022年7月29日8:00-18:00" class="query-group-cust" style="width:100%"  v-model="msgModel.msgTime"></a-input></p> 
       <p> 通知来源：<a-input placeholder="通知来源：" class="query-group-cust" style="width:100%"  v-model="msgModel.msgForm"></a-input></p> 
      <a-textarea :rows="5" v-model="msgModel.msgContent" placeholder="请输入停水区域通知内容"/>           
    </a-modal>

    <arc-account-modal ref="modalForm" @ok="modalFormOk"></arc-account-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { httpAction, getAction } from '@/api/manage'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import ArcAccountModal from './modules/ArcAccountModal'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'

  export default {
    name: 'ArcAccountList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      ArcAccountModal
    },
    data () {
      return {
        description: '缴费账户管理页面',
        textMaxLength:12,

        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'缴费账号',
            align:"center",
            dataIndex: 'code'
          },
          {
            title:'账户类型',
            align:"center",
            dataIndex: 'feeCusType_dictText'
          },
          {
            title:'姓名',
            align:"center",
            dataIndex: 'contactId_dictText',
            scopedSlots: {customRender: "ellipsisText"}
          },
          // {
          //   title:'银行账号',
          //   align:"center",
          //   dataIndex: 'bankAccountNo'
          // },
          // {
          //   title:'开户行',
          //   align:"center",
          //   dataIndex: 'bank'
          // },
          {
            title:'是否预存户',
            align:"center",
            dataIndex: 'isStored_dictText'
          },
          // {
          //   title:'预存协议号',
          //   align:"center",
          //   dataIndex: 'storedContractNo'
          // },
          // {
          //   title:'预存开始时间',
          //   align:"center",
          //   dataIndex: 'storedBeginTime'
          // },
          // {
          //   title:'预存结束时间',
          //   align:"center",
          //   dataIndex: 'storedEndTime'
          // },
          // {
          //   title:'预存创建时间',
          //   align:"center",
          //   dataIndex: 'storedCreatedTime'
          // },
          // {
          //   title:'预存创建人',
          //   align:"center",
          //   dataIndex: 'storedCreatorId'
          // },
          // {
          //   title:'滚存金额',
          //   align:"center",
          //   dataIndex: 'roundBalance'
          // },
          {
            title:'是否托收',
            align:"center",
            dataIndex: 'isProxy_dictText'
          },
          // {
          //   title:'托收单位',
          //   align:"center",
          //   dataIndex: 'feeProxyUnit'
          // },
          {
            title:'是否预开票',
            align:"center",
            dataIndex: 'isPreInvoiced_dictText'
          },
          {
            title:'是否增值税',
            align:"center",
            dataIndex: 'isVat_dictText'
          },
          // {
          //   title:'增值税号',
          //   align:"center",
          //   dataIndex: 'vatNo'
          // },
          // {
          //   title:'银行合同号',
          //   align:"center",
          //   dataIndex: 'bankcontractno'
          // },
          // {
          //   title:'开户行号',
          //   align:"center",
          //   dataIndex: 'bankno'
          // },
          // {
          //   title:'托收户是否审核',
          //   align:"center",
          //   dataIndex: 'isExamine_dictText'
          // },
          // {
          //   title:'银行开户名称',
          //   align:"center",
          //   dataIndex: 'bankaccountname'
          // },
          // {
          //   title:'银行开启时间',
          //   align:"center",
          //   dataIndex: 'bankOpendTime'
          // },
          // {
          //   title:'状态',
          //   align:"center",
          //   dataIndex: 'status'
          // },
          {
            title:'微信账户',
            align:"center",
            dataIndex: 'weixinId',
            scopedSlots: {customRender: "ellipsisText"}
          },
          {
            title:'是否代扣',
            align:"center",
            dataIndex: 'isWithhold_dictText'
          },
          // {
          //   title:'代扣银行',
          //   align:"center",
          //   dataIndex: 'withholdBank'
          // },
          {
            title:'账户余额',
            align:"center",
            dataIndex: 'balance'
          },
          {
            title:'账户状态',
            align:"center",
            dataIndex: 'waterUserStatus_dictText'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        wxtStopVisible: false,
        msgModel:{
          msgType:'',
          msgTime:'',
          msgContent:'',
          msgForm:''
        },    
        url: {
          list: "/arc/arcAccount/list",
          msgStop: '/arc/arcAccount/wxmsgStop',
          cancelBind: "/arc/arcAccount/cancelBind",
          delete: "/arc/arcAccount/delete",
          deleteBatch: "/arc/arcAccount/deleteBatch",
          exportXlsUrl: "/arc/arcAccount/exportXls",
          importExcelUrl: "arc/arcAccount/importExcel",

        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      handleMeter(rowKey){
        this.$router.push({path: '/modules/arc/ArcAccountMeterList/'+rowKey})
      },
      handleTabDetail(rowKey){
        this.$router.push({path: '/modules/arc/ArcAccRelatedInfo/'+rowKey})
      },

      //解除绑定
      handleCancelBind(row){
        const that = this;
        that.loading = true;
        httpAction(that.url.cancelBind,row,'post').then((res)=>{
          if(res.success){
            that.$message.success(res.message);
          }else{
            that.$message.warning(res.message);
          }
        }).finally(() => {
          that.loading = false;
        })
      },

      handleMsgStop(){
        this.wxtStopVisible=true;
      },
      handleWxtStopOk(){      
        if(this.msgModel.msgContent ){
            let params = this.getQueryParams();//查询条件
            params.msgContent=this.msgModel.msgContent;
            params.msgType=this.msgModel.msgType;
            params.msgTime=this.msgModel.msgTime;
            params.msgForm=this.msgModel.msgForm;
            this.loading = true;
            console.log("params:",params);
            getAction(this.url.msgStop, params).then((res) => {
              if (res.success) {
                this.$message.success(res.message)
              }else{
                this.$message.warning(res.message)
              }
            }).finally(() => {
              this.loading = false
            })
        }
      },

      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'code',text:'缴费账号',dictCode:''})
        fieldList.push({type:'string',value:'feeCusType',text:'账户类型',dictCode:'fee_cus_type'})
        fieldList.push({type:'sel_search',value:'contactId',text:'用户档案',dictTable:'mws_t_arc_contacts', dictText:'name', dictCode:'id'})
        fieldList.push({type:'string',value:'bankAccountNo',text:'银行账号',dictCode:''})
        fieldList.push({type:'string',value:'bank',text:'开户行',dictCode:''})
        fieldList.push({type:'string',value:'waterUserStatus',text:'账户状态',dictCode:'water_user_status'})
        fieldList.push({type:'int',value:'isStored',text:'是否预存账户',dictCode:'yn'})
        fieldList.push({type:'string',value:'storedContractNo',text:'预存协议号',dictCode:''})
        fieldList.push({type:'string',value:'storedBeginTime',text:'预存开始时间',dictCode:''})
        fieldList.push({type:'string',value:'storedEndTime',text:'预存结束时间',dictCode:''})
        fieldList.push({type:'string',value:'storedCreatedTime',text:'预存创建时间',dictCode:''})
        fieldList.push({type:'string',value:'storedCreatorId',text:'预存创建人',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'balance',text:'账户余额',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'roundBalance',text:'滚存金额',dictCode:''})
        fieldList.push({type:'int',value:'isProxy',text:'是否托收',dictCode:'yn'})
        fieldList.push({type:'string',value:'feeProxyUnit',text:'托收单位ID',dictCode:'fee_proxy_unit'})
        fieldList.push({type:'BigDecimal',value:'isPreInvoiced',text:'是否预开票',dictCode:'yn'})
        fieldList.push({type:'int',value:'isVat',text:'是否增值税',dictCode:'yn'})
        fieldList.push({type:'string',value:'vatNo',text:'增值税号',dictCode:''})
        fieldList.push({type:'string',value:'bankcontractno',text:'银行合同号',dictCode:''})
        fieldList.push({type:'string',value:'bankno',text:'开户行号',dictCode:''})
        fieldList.push({type:'int',value:'isExamine',text:'托收户是否审核',dictCode:'yn'})
        fieldList.push({type:'string',value:'bankaccountname',text:'银行开户名称',dictCode:''})
        fieldList.push({type:'string',value:'bankOpendTime',text:'银行开启时间',dictCode:''})
        fieldList.push({type:'int',value:'status',text:'状态',dictCode:''})
        fieldList.push({type:'string',value:'weixinId',text:'微信账户ID',dictCode:''})
        fieldList.push({type:'int',value:'isWithhold',text:'是否银行代扣',dictCode:'yn'})
        fieldList.push({type:'string',value:'withholdBank',text:'代扣银行',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>